/*
 * @Description: 
 * @Author: houcw
 * @Date: 2023-11-09 10:34:28
 * @LastEditTime: 2023-11-09 17:45:11
 * @LastEditors: houcw
 * @Reference: 
 */
import { reactive, ref } from "vue";
import { ElMessage, ElMessageBox } from "element-plus";
function tablePageSetting(apiName) {
    const headerStyle = ref({
        background: "rgb(230, 243, 255)",
        color: "rgb(55, 59, 131)",
        fontWeight: 500,
    });
    const tableData = ref([]);
    const total = ref(0)
    const loading = ref(false)
    const page = reactive({
        page: 1,
        size: 10,
    });
    const query = ref({})
    const date = ref('')
    function handleCurrentChange(val) {
        page.page = val;
        getList();
    }
    async function getList() {
        loading.value = true;
        const res = await apiName({ ...page, ...query.value })
        console.log(res)
        try {
            if (res.code == 200 && res.data) {
                tableData.value = res.data.list || [];
                total.value = res.data.total || 0;
            }
            loading.value = false;
        } catch (error) {
            loading.value = false;
        }

    }
    // 筛选
    function handleSearch() {
        page.page = 1
        getList();
    }
    // 重置
    function handleReset() {
        date.value = ''
        query.value = {};
        handleSearch();
    }
    // 表格按钮二次确认
    function handelConfirmFun(index, row, title, callback, type = 1) {
        ElMessageBox.confirm(title, "提示", {
            confirmButtonText: "确认",
            cancelButtonText: "取消",
            type: "warning",
        })
            .then(() => {
                callback({ index, row, type })
            })
            .catch(() => {

            });
    }

    return {
        headerStyle,
        page,
        query,
        tableData,
        total,
        loading,
        date,
        handleCurrentChange,
        getList,
        handelConfirmFun,
        handleSearch,
        handleReset
    };
}
export default tablePageSetting;